package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopRangeDto;
import com.java110.po.shop.ShopRangePo;
import com.java110.mall.shop.bmo.shopRange.IDeleteShopRangeBMO;
import com.java110.mall.shop.bmo.shopRange.IGetShopRangeBMO;
import com.java110.mall.shop.bmo.shopRange.ISaveShopRangeBMO;
import com.java110.mall.shop.bmo.shopRange.IUpdateShopRangeBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping(value = "/shopRange")
public class ShopRangeApi {

    @Autowired
    private ISaveShopRangeBMO saveShopRangeBMOImpl;
    @Autowired
    private IUpdateShopRangeBMO updateShopRangeBMOImpl;
    @Autowired
    private IDeleteShopRangeBMO deleteShopRangeBMOImpl;

    @Autowired
    private IGetShopRangeBMO getShopRangeBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /shopRange/saveShopRange
     * @path /app/shopRange/saveShopRange
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveShopRange", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopRange(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "rangeName", "请求报文中未包含rangeName");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");


        ShopRangePo shopRangePo = BeanConvertUtil.covertBean(reqJson, ShopRangePo.class);
        return saveShopRangeBMOImpl.save(shopRangePo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /shopRange/updateShopRange
     * @path /app/shopRange/updateShopRange
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateShopRange", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopRange(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "rangeName", "请求报文中未包含rangeName");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");
        Assert.hasKeyAndValue(reqJson, "shopRangeId", "shopRangeId不能为空");


        ShopRangePo shopRangePo = BeanConvertUtil.covertBean(reqJson, ShopRangePo.class);
        return updateShopRangeBMOImpl.update(shopRangePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopRange/deleteShopRange
     * @path /app/shopRange/deleteShopRange
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteShopRange", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopRange(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "shopRangeId", "shopRangeId不能为空");


        ShopRangePo shopRangePo = BeanConvertUtil.covertBean(reqJson, ShopRangePo.class);
        return deleteShopRangeBMOImpl.delete(shopRangePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopRange/queryShopRange
     * @path /app/shopRange/queryShopRange
     * @param
     * @return
     */
    @RequestMapping(value = "/queryShopRange", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopRange(@RequestParam(value = "shopRangeId", required = false) String shopRangeId,
                                                 @RequestParam(value = "shopTypeId", required = false) String shopTypeId,
                                                 @RequestParam(value = "rangeName", required = false) String rangeName,
                                                 @RequestParam(value = "isShow", required = false) String isShow,
                                                 @RequestParam(value = "isDefault", required = false) String isDefault,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        ShopRangeDto shopRangeDto = new ShopRangeDto();
        shopRangeDto.setShopRangeId(shopRangeId);
        shopRangeDto.setShopTypeId(shopTypeId);
        shopRangeDto.setRangeName(rangeName);
        shopRangeDto.setIsShow(isShow);
        shopRangeDto.setIsDefault(isDefault);
        shopRangeDto.setPage(page);
        shopRangeDto.setRow(row);
        return getShopRangeBMOImpl.get(shopRangeDto);
    }
}
